//
//  LYMessageModel.swift
//  WeChat
//
//  Created by mac on 2018/7/26.
//  Copyright © 2018年 RRC. All rights reserved.
//

import UIKit
import SwiftyJSON

class LYMessageModel: NSObject {
    var middleImageURL: String?
    var unreadNumber : Int?
    var nickName : String?
    var messageFromType : MessageFromType = .Personal
    var messageContentType : MessageContentType = .Text
    var chatId : String?
    var latestMessage : String?
    var dateString: String?
    
    
    var lastMessage: String? {
        get {
            switch (self.messageContentType) {
            case .Text, .System:
                return self.latestMessage
            case .Image:
                return "[图片]"
            case .Voice:
                return "[语音]"
            case .File:
                return "[文件]"
            default:
                return ""
            }
        }
    }
    
    init(jsonData:JSON){
        super.init()
        middleImageURL = jsonData["avatar_url"].string
        unreadNumber = jsonData["message_unread_num"].int
        nickName = jsonData["nickname"].string
        messageContentType = MessageContentType(rawValue: jsonData["last_message","message_content_type"].string!)!
        latestMessage = jsonData["last_message"]["message"].string
        messageFromType = MessageFromType(rawValue: jsonData["meesage_from_type"].string!)!
        dateString = jsonData["last_message","ctime"].string
    }
    
}
